package com.group4.gps;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;

import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;


/**
 * Uses Google maps to display a map and paints the tracked path onto the map.
 * Can switch between showing the map as Street view or as Satellite view.
 * 
 */
public class MapViewActivity extends MapActivity{

	private ArrayList<String> latitudes;
	private ArrayList<String> longitudes;
	private MapView mapView;
	private MapOverlay ourMapOverlay;
	private CheckBox checkSatellite;
		
	/**
	 * Displays a screen with a toggle button and Google maps integrated. Paints the path as an overlay
	 * on top of the map. 
	 */
	@Override
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.mapview);
		mapView = (MapView) findViewById(R.id.mapview1);    
		mapView.setBuiltInZoomControls(true);
		mapView.setSatellite(false);
				
		checkSatellite = (CheckBox) findViewById(R.id.satelliteview);
		checkSatellite.setOnClickListener(new View.OnClickListener()
        {
	           public void onClick(View v)
	            {
	                SetSatellite();
	            }
	        });

		TrackerDatabase database = new TrackerDatabase(this);
		database.open();
		latitudes = database.fetchAllLatitudes();
		database.close();
		database.open();
		
		longitudes = database.fetchAllLongitudes();
		database.close();
		
		ourMapOverlay = new MapOverlay(latitudes, longitudes, mapView);
		List<Overlay> listOfOverlays = mapView.getOverlays();
		listOfOverlays.clear();
		listOfOverlays.add(ourMapOverlay);
		mapView.invalidate(); 	
	}
	
	/**
	 * Switch between Street view and Satellite view.
	 * 
	 */
	private void SetSatellite()
	{
		mapView.setSatellite(checkSatellite.isChecked());
	};
	
	//Must exist because of MapActivity
	@Override
	protected boolean isRouteDisplayed() {
		// TODO Auto-generated method stub
		return false;
	}

}
